<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../config.inc.php");
$_DBSite = "Result";
$_LangPath = "oddslog";
include_once(__Admin_Path."/logincheck.php");
include_once(__Language_Path."/selectlanguage_admin.php");
include_once(__Modules_Path."/Lotto.lib.php");
include_once(__Modules_Path."/BetType.lib.php");
include_once(__Modules_Path."/ChangeTime.lib.php");
include_once(__Common_Path."/Lotto.inc.php");
include_once(__Common_Path."/betparam/AnimalsParams_1.inc.php");

$intBetType = intval($_data["BetType"]);
$intLottoID = intval($_data["LottoID"]);
$intGambleID = intval($_data["GambleID"]);
$intSortType = intval($_data["SortType"]);
if($intLottoID <= 0)$intLottoID = $_MemInitLottoID;
if($intLottoID <= 0)$intLottoID = 1;
$intLType = $_arrLotto[$intLottoID]["LType"];
if($intBetType <= 0){
	list($intBT, $strBT) = each($_arrBet_Type[$intLType]);
	$intBetType = $intBT;
}

$strSQL = "select * from `bet_Odds` where LottoID = '".$intLottoID."' and GambleID = '".$intGambleID."' and (Bet_Type = '".$intBetType."' or Memo like 'S-".$intGambleID."-".$intBetType."-%') order by ID desc";
if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Find Odds Log Error!!";
	$GLOBALS["errorhidden"] = "\n Error: ".mysql_error($$_Conn).",\nSQL: ".$strSQL.",\nLine: ".__LINE__.",\nPage: ".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}

$fp = @file(__Admintemplate_Path."/tempOdds.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);

while(list($k, $v) = each($_strOddsLog)){
	$fp = str_replace("{".$k."}", $v, $fp);
}

$strSelect = MakeLottoSelect($_arrLotto, $intLottoID, "LottoID", "document.SearchFrm.submit();", $_intLang);
$fp = str_replace("{SelectLottoType}", $strSelect, $fp);

$strSelect = MakeGambleNoSelect($intLottoID, $intGambleID, "GambleID", "", 4, $_arrLotto);
$fp = str_replace("{SelectGambleNo}", $strSelect, $fp);

$strSelect = SelectBetType($intBetType, "BetType", "", $intLType);
$fp = str_replace("{SelectBetType}", $strSelect, $fp);

//內容清單
$strCon = "";
$strTmp = "";
$intSum = 0;
preg_match("/<!-- @ Content Start @ \/\/-->(.+)<!-- @ Content End @ \/\/-->/s", $fp, $arrMatch);
while($objOdds = PMA_mysql_fetch_object($RS)){
	$intSum++;
	$strTmp = $arrMatch[1];
	$strTime = DateForm($objOdds -> AddDate, $objOdds -> AddTime, "Y-m-d H:i:s", "UToC");
	$strBT = "";
	$strOCon = "";
	if($objOdds -> Bet_Type > 0){
		$strBT = $_arrBet_Type[$intLType][$objOdds -> Bet_Type];
		$strOCon = ChangeType($objOdds -> Bet_Type, $objOdds -> Number)."&nbsp;@&nbsp;".$objOdds -> Odds;

	}elseif($objOdds -> Bet_Type == -2){
		$strBT = $_strOddsLog["Switch"];//"開關";

		$arrMemo = split("-", $objOdds -> Memo);
		$arrNum = split(",", $arrMemo[3]);
		$arrT = array();
		foreach($arrNum as $key => $val){
			$arrT[$key] = ChangeType($arrMemo[2], $val);
			if($arrT[$key] == ""){
				unset($arrT[$key]);
				continue;
			}
			if($key != 0 && $key % 10 == 0)$arrT[$key] = "<br>\n".$arrT[$key];
		}
		$strOCon = join(",", $arrT);
		if(sizeof($arrT) > 10)$strOCon .= "<br>\n";
		$strOCon .= "<a style=\"color:#FF0000\">";
		$strOCon .= ($arrMemo[4] == "1")?"&nbsp;".$_strOddsLog["Stop"]:"&nbsp;".$_strOddsLog["Open"];
		$strOCon .= "</a>";		
	} //if($objOdds -> Bet_Type > 0){

	$strTmp = str_replace("{ShowID}", $objOdds -> ID, $strTmp);
	$strTmp = str_replace("{ShowTime}", $strTime, $strTmp);
	$strTmp = str_replace("{ShowUser}", $objOdds -> UserAccount, $strTmp);
	$strTmp = str_replace("{ShowKind}", $strBT, $strTmp);
	$strTmp = str_replace("{ShowContent}", $strOCon, $strTmp);
	$strTmp = str_replace("{ShowIP}", $objOdds -> OpIP, $strTmp);
	$strCon .= $strTmp."\n";
} //while($objOdds = mysql_fetch_object($RS))

$fp = str_replace("{Sum_MNo}", $intSum, $fp);
$fp = preg_replace("/<!-- @ Content Start @ \/\/-->.+<!-- @ Content End @ \/\/-->/s", $strCon, $fp);

//輸出
WebOutputHTML($fp, 1);

function ChangeType($intBT, $intNum){
	global $_arrBet_Type, $_arrAnimals, $_strSame_String, $intLType;
	$strTmp = "";
	if(($intBT >= 12 && $intBT <= 14) || $intBT == 27){
		$strTmp = $_arrBet_Type[4]." ".floor($intNum / 10)." ";
	}

	switch($intLType){
		case 1:
			switch($intBT){
				case 1:
				case 4:
				case 21:
				case 22:
				case 23:
				case 24:
				case 25:
				case 26:
				case 28:
					return sprintf("%02s", $intNum);
					break;

				case 2:
				case 5:
				case 12:
					if((int)$intNum %10 == 2)return;		
					return ((int)$intNum % 10 == 0)?($strTmp.$_strSame_String[Odd]):($strTmp.$_strSame_String[Even]);
					break;

				case 3:
				case 6:
				case 13:
					if((int)$intNum %10 == 2)return;
					return ((int)$intNum %10 == 0)?$strTmp.$_strSame_String[Over]:$strTmp.$_strSame_String[Under];
					break;

				case 16:
				case 27:
					if((int)$intNum %10 == 2)return;
					return ((int)$intNum %10 == 0)?$strTmp.$_strSame_String[SOdd]:$strTmp.$_strSame_String[SEven];
					break;

				case 7:
				case 8:
				case 9:
				case 10:
				case 11:
					if((int)$intNum == 1)return;
					return $_arrBet_Type[$intBT];
					break;

				case 17:
					if((int)$intNum > 2)return;
				case 14:
					if((int)$intNum % 10 == 0)return $strTmp.$_strSame_String[Color0];
					if((int)$intNum % 10 == 1)return $strTmp.$_strSame_String[Color1];
					if((int)$intNum % 10 == 2)return $strTmp.$_strSame_String[Color2];
					break;

				case 18:
				case 19:
					return $_arrAnimals[$intNum];
					break;

				case 20:
					return $intNum.$_strSame_String[Mantissa];
					break;

				case 29:
					return $_strSame_String["SHelfColor".$intNum];
					break;

				case 30:
					return ((int)$intNum == 0)?$strTmp.$_strSame_String[Win]:$strTmp.$_strSame_String[NoWin];
					break;
			}
			break;

		case 2:
			switch($intBT){
				case 64:
				case 65:
				case 66:
					return sprintf("%02s", $intNum);
					break;

				case 51:
				case 54:
				case 57:
				case 60:
				case 61:
				case 69:
				case 70:
				case 71:
				case 72:
				case 73:
				case 74:
				case 75:
				case 76:
				case 77:
				case 90:
				case 91:
					return sprintf("%01s", $intNum);
					break;

				case 92:
				case 93:
					return sprintf("%03s", $intNum);
					break;

				case 52:
				case 55:
				case 58:
				case 62:
					if((int)$intNum %10 == 2)return;		
					return ((int)$intNum % 10 == 0)?($strTmp.$_strSame_String[Odd]):($strTmp.$_strSame_String[Even]);
					break;

				case 53:
				case 56:
				case 59:
				case 63:
					if((int)$intNum %10 == 2)return;
					return ((int)$intNum %10 == 0)?$strTmp.$_strSame_String[Over]:$strTmp.$_strSame_String[Under];
					break;

				case 84:
				case 85:
				case 86:
					return ((int)$intNum == 1 || (int)$intNum == 2 || (int)$intNum == 3 || (int)$intNum == 5 || (int)$intNum == 7)?$strTmp.$_strSame_String[Prime]:$strTmp.$_strSame_String[Composite];
					break;

				case 87:
					return $_strSame_String["OEParlay".$intNum];
					break;

				case 88:
					return $_strSame_String["OUParlay".$intNum];
					break;

				case 89:
					return $_strSame_String["PCParlay".$intNum];
					break;
			}
			break;

		case 3:
			switch($intBT){
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
				case 12:
					return sprintf("%02s", $intNum);
					break;

				case 7:
				case 8:
				case 9:
				case 10:
				case 13:
					return sprintf("%03s", $intNum);
					break;

				case 11:
					return sprintf("%04s", $intNum);
					break;

				case 18:
				case 19:
				case 20:
				case 21:
				case 22:
					return sprintf("%01s", $intNum);
					break;

				case 14:
				case 16:
					if((int)$intNum %10 == 2)return;		
					return ((int)$intNum % 10 == 0)?($strTmp.$_strSame_String[Odd]):($strTmp.$_strSame_String[Even]);
					break;

				case 15:
				case 17:
					if((int)$intNum %10 == 2)return;
					return ((int)$intNum %10 == 0)?$strTmp.$_strSame_String[Over]:$strTmp.$_strSame_String[Under];
					break;
			}
			break;
	}

	return$intNum;
}
?>